//GALocalizationHandler.getRelativeString(Core.Localization.getString("TZ_MESSAGE_OFFERS_COINS_BUCKS"),[totalCoinsDiff,totalBucksDiff]);
exports.MMGameLayer = Core.Class.singleton(
{
	classname: 'MMGameLayer',
	
	initialize: function()
	{
		this._baseLayer = null;
		this._controlLayer = null;
		this._background = null;
		this._mallContainer = null;
		
		this._baseLayer = new GL2.Node();
		GL2.Root.addChild(this._baseLayer);
		
		this.addBackground();
	},
	
	startGame: function(mallModel)
	{
		this._controlLayer = new MMControlLayer();
		this._controlLayer.setDepth(2);
		this._controlLayer.createView();
		this.addChild(this._controlLayer);
		
		this._mallContainer = new MallContainer();
		this._mallContainer.setDepth(1);
		var positionY = TCUtil.getScreenHeight() - TCUtil.getAdjustedY(this._controlLayer.getBottomBarHeight());
		this._mallContainer.setPosition([TCUtil.getAdjustedX(0),positionY]);
		
		var sizeHeight = positionY - TCUtil.getAdjustedY(this._controlLayer.getTopBarHeight());
		this._mallContainer.setSize(new Core.Vector(TCUtil.getScreenWidth(), sizeHeight));
		
		this._mallContainer.createView();
		this._mallContainer.loadMallWithModel(mallModel);
		this.addChild(this._mallContainer);
		this._controlLayer.getTopBar().updateTopBar();
		this.shouldShowAlertForNewItems();
		this.showAlertForHelping();
		if(!DatabaseInterface._isVisitingNeighbor)
		{
			TutorialManager.startTurorialAtCurrentStep();
		}
		else
		{
			if(!TutorialManager.getHasCompletedTutorial())
			{
				this._controlLayer.getBottomBar().showTutorialForSocialActions();
			}
		}
	},
	
	showAlertForHelping: function()
	{
		MMFriendActionManager.rewardUserForHelpingFriend();
	},
	
	shouldShowAlertForNewItems: function()
	{
		if(!DatabaseInterface._isVisitingNeighbor)
		{
			var user = MMGameState.getCurrentUser();
			var alert = false;
			var storeItems = GAGameLoader.getStoreHandler().getAllItems(1 , 1 , true);
			for (var i = 0; i < storeItems.length; i++)
			{
				var storeItem = storeItems[i]; 
				if(storeItem)
				{
					if(user.isUnlockedItemNew(storeItem))
					{
						user.saveUnlockedItemToUserDefaults(storeItem);
						alert = true;
					}
				}
			}
			if(alert)
			{
				UIFactory.getAlertBox(Core.Localization.getString("MESSAGE"), Core.Localization.getString("NEW_SHOPS_OPENED"), ["ok"], null);
			}
		}
	},
 	 	
	showMallListUI: function()
	{
		var mallMainView = new MallMainView();
		mallMainView.createView();
		NGWindow.document.addChild(mallMainView);
	},
	
	getMallUI : function() 
	{
		if(this._mallContainer)
		{
			return this._mallContainer.getMallUI();
		}
		return null;
	},
	
	getMallContainer: function()
	{
		if(this._mallContainer)
		{
			return this._mallContainer;
		}
		return null;
	},
	
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/";
	},
	
	addBackground: function()
	{
		var path = this.getBaseResourcePath() + "mall-background.png";
		this._background = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(0)], null, path, [TCUtil.getScreenWidth(),TCUtil.getScreenHeight()]);
		this.addChild(this._background);
	},
	
	addChild: function(node) {
		this._baseLayer.addChild(node);
	},
	
	getControlLayer: function()
	{
		if(this._controlLayer) {
			return this._controlLayer;
		}
		return null;
	},
	
	destroyAllChildren: function()
	{
		if(this._controlLayer) 
		{
			this._controlLayer.destroy();
			this._controlLayer = null;
		}
//		if(this._background) 
//		{
//			this._background.destroy();
//			this._background = null;
//		}
		if(this._mallContainer)
		{
			this._mallContainer.destroy();
			this._mallContainer = null;
		}
		
	},
	
	destroy: function()
	{
		if(this._controlLayer) 
		{
			this._controlLayer.destroy();
			this._controlLayer = null;
		}
		if(this._background) 
		{
			this._background.destroy();
			this._background = null;
		}
		if(this._mallContainer)
		{
			this._mallContainer.destroy();
			this._mallContainer = null;
		}
	},
});
	